#
# Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
#
import os

Import('CfgmEnv')
env = CfgmEnv.Clone()

sources = [
    'setup.py',
    'requirements.txt',
    'run_tests.sh',
    'test-requirements.txt',
    '.testr.conf',
    '.coveragerc',
    'MANIFEST.in',
    'svc_monitor/__init__.py',
    'svc_monitor/agent.py',
    'svc_monitor/agent_manager.py',
    'svc_monitor/svc_monitor.py',
    'svc_monitor/instance_manager.py',
    'svc_monitor/virtual_machine_manager.py',
    'svc_monitor/vrouter_instance_manager.py',
    'svc_monitor/physical_service_manager.py',
    'svc_monitor/config_db.py',
    'svc_monitor/db.py',
    'svc_monitor/loadbalancer_agent.py',
    'svc_monitor/logger.py',
    'svc_monitor/nova_client.py',
    'svc_monitor/port_tuple.py',
    'svc_monitor/reaction_map.py',
    'svc_monitor/module_logger.py',
    'svc_monitor/scheduler/__init__.py',
    'svc_monitor/scheduler/vrouter_scheduler.py',
    'svc_monitor/services/__init__.py',
    'svc_monitor/services/loadbalancer/__init__.py',
    'svc_monitor/services/loadbalancer/drivers/__init__.py',
    'svc_monitor/services/loadbalancer/drivers/abstract_driver.py',
    'svc_monitor/services/loadbalancer/drivers/f5/__init__.py',
    'svc_monitor/services/loadbalancer/drivers/f5/f5_driver.py',
    'svc_monitor/services/loadbalancer/drivers/f5/f5_driver_v2.py',
    'svc_monitor/services/loadbalancer/drivers/native/__init__.py',
    'svc_monitor/services/loadbalancer/drivers/native/driver.py',
    'svc_monitor/services/loadbalancer/drivers/ha_proxy/__init__.py',
    'svc_monitor/services/loadbalancer/drivers/ha_proxy/driver.py',
    'svc_monitor/services/loadbalancer/drivers/ha_proxy/haproxy_config.py',
    'svc_monitor/services/loadbalancer/drivers/ha_proxy/custom_attributes/custom_attributes.yml',
    'svc_monitor/services/loadbalancer/drivers/ha_proxy/custom_attributes/__init__.py',
    'svc_monitor/services/loadbalancer/drivers/ha_proxy/custom_attributes/haproxy_validator.py',
    'svc_monitor/snat_agent.py',
    'svc_monitor/tests/__init__.py',
    'svc_monitor/tests/test_common_utils.py',
    'svc_monitor/tests/test_svc_monitor.py',
    'svc_monitor/tests/test_vrouter_instance_manager.py',
    'svc_monitor/tests/test_virtual_machine_manager.py',
    'svc_monitor/tests/test_dep_track.py',
    'svc_monitor/tests/test_ha_proxy.py',
    'svc_monitor/tests/test_snat.py',
    'svc_monitor/tests/test_snat_agent.py',
    'svc_monitor/tests/test_loadbalancer_agent.py',
    'svc_monitor/tests/test_config_db.py',
    'svc_monitor/tests/test_f5_lb.py',
    'svc_monitor/tests/test_port_tuple.py',
    'svc_monitor/tests/fake_lb_driver.py',
    'svc_monitor/tests/scheduler/__init__.py',
    'svc_monitor/tests/scheduler/test_vrouter_schedulers.py',
    'svc_monitor/tests/test_lbaas_custom_attributes.py',
]

sources += env.SandeshGenPy('svc_mon_introspect.sandesh',
                            'svc_monitor/sandesh/', False)
sources += env.SandeshGenPy('#controller/src/vnsw/agent/uve/loadbalancer.sandesh',
                            'svc_monitor/sandesh/', False)
sources += env.SandeshGenPy('port_tuple.sandesh',
                            'svc_monitor/sandesh/', False)
sources += env.SandeshGenPy('snat_agent.sandesh',
                            'svc_monitor/sandesh/', False)

cd_cmd = 'cd ' + Dir('.').path + ' && '
sdist_gen = env.Command('dist/svc_monitor-0.1dev.tar.gz',
                        sources,
                        cd_cmd + 'python setup.py sdist')
env.Alias('controller/src/config/svc_monitor:sdist', sdist_gen)

packages = [
    '%s/%s' % (env['TOP'], env.GetVncAPIPkg()),
    '%s/config/common/dist/cfgm_common-0.1dev.tar.gz' % env['TOP'],
    '%s/sandesh/common/dist/sandesh-common-0.1dev.tar.gz' % env['TOP'],
    '%s/tools/sandesh/library/python/dist/sandesh-0.1dev.tar.gz' % env['TOP'],
]

# Documentation
doc_files = []
doc_files += env.SandeshGenDoc('svc_mon_introspect.sandesh')
doc_files += env['CFGM_DOC_FILES']
doc_files += env.SandeshGenDoc('#controller/src/vnsw/agent/uve/loadbalancer.sandesh')
doc_files += env['CFGM_DOC_FILES']
doc_files += env.SandeshGenDoc('port_tuple.sandesh')
doc_files += env.SandeshGenDoc('snat_agent.sandesh')

if 'install' in BUILD_TARGETS:
    install_cmd = env.Command(None, sources,
                              cd_cmd + 'python setup.py install %s' %
                              env['PYTHON_INSTALL_OPT'])
    env.Alias('install', install_cmd)

env.Alias('install', env.Install(env['INSTALL_CONF'], 'contrail-svc-monitor.conf'))
env.Alias('install', env.InstallAs( env['INSTALL_INITD'] +
    '/contrail-svc-monitor', 'contrail-svc-monitor.initd.supervisord'))
env.Alias('install', env.InstallAs( env['INSTALL_SYSTEMD'] +
    '/contrail-svc-monitor.service', 'systemd/contrail-svc-monitor.service'))
env.Alias('install', env.Install(env['INSTALL_CONF']+
    '/supervisord_config_files', 'contrail-svc-monitor.ini'))
env.Alias('install', env.Install(
    env['INSTALL_MESSAGE_DOC'] + '/contrail-svc-monitor/', doc_files))

test_target = env.SetupPyTestSuite(sdist_gen, '/config/api-server/dist/contrail-api-server-0.1dev.tar.gz')

# SetupPyTestSuite* methods don't return any targets (see review 40381)
# so until it's merged we add the broken target here directly, by referencing
# a target created by SetupPyTestSuite.
test_target = env['TOP'][1:] + '/config/svc-monitor:test'
env.Alias('controller/src/config/svc-monitor/svc_monitor:test', test_target)
env.Alias('controller/src/config/svc_monitor:test', test_target)

# Local Variables:
# mode: python
# End:
